<?php
class workdaysFilter
{	function getLike()
	{		$like='';
		$like1='';
		if(isset($_POST['filter']))
		{
			if($_POST['filter']=='byWorkdays')
			{
				$time=$_POST['worktime'];
				$wd=$_POST['weekday'];
				if($time>10)
				{
					for($i=$time; $i<24; $i++)
					{
						$time=$i;
						if($i<10)$time='0'.$i;
						$like[]="address LIKE '%notevery~%".$wd."&%-".$time.":%&%'";
						$like1[]="address LIKE '%alldays~%-".$time.":%'";
					}
					for($i=0; $i<11; $i++)
					{
						$time=$i;
						if($i<10)$time='0'.$i;
						$like[]="address LIKE '%notevery~%".$wd."&%-".$time.":%&%'";
						$like1[]="address LIKE '%alldays~%-".$time.":%'";
					}
				}
				else
				{
					for($i=$time; $i<11; $i++)
					{
						$time=$i;
						if($i<10)$time='0'.$i;
						$like[]="address LIKE '%notevery~%".$wd."&%-".$time.":%&%'";
						$like1[]="address LIKE '%alldays~%-".$time.":%'";
					}
				}
				if($like)$like="AND (".implode(' || ', $like)." || ".implode(' || ', $like1)." || address LIKE '%^24%')";
			}
		}
		return $like;	}
	function wdCheck($address, $minPosition)
	{
		$wdCheck=false;
		$address=explode('|', $address);
		foreach($address as $key=>$addr)
		{
			$addrEls=explode('^', $addr);
			if($addrEls[5]==$minPosition)
			{
				$workdays=$addrEls[4];
				$wdCheck=$this->wdch($workdays);
			}
		}
		return $wdCheck;
	}
	function wdch($workdays)
	{		$wdCheck=false;		if($workdays==24)$wdCheck=true;
		else
		{
			$wd=explode('~', $workdays);
			if($wd[0]=='alldays')
			{
				$fromTo=explode('-', $wd[1]);
				$toEls=explode(':', $fromTo[1]);
				$toHour=$toEls[0];
				if($_POST['worktime']<8 && $_POST['worktime']>=0)
				{
					if($toHour<8 && $toHour>=0 && $toHour>=$_POST['worktime'])$wdCheck=true;
				}
				if($_POST['worktime']>8 && $_POST['worktime']<24)
				{
					if($toHour>8 && $toHour<24 && $toHour>=$_POST['worktime'])$wdCheck=true;
				}
			}
			elseif($wd[0]=='notevery')
			{
				$wday=explode('$', $wd[1]);
				foreach($wday as $key=>$day)
				{
					$dayEls=explode('&', $day);
					if($dayEls[0]==$_POST['weekday'])
					{
						$fromTo=explode('-', $dayEls[1]);
						$toEls=explode(':', $fromTo[1]);
						$toHour=$toEls[0];
						if($_POST['worktime']<8 && $_POST['worktime']>=0)
						{
							if($toHour<8 && $toHour>=0 && $toHour>=$_POST['worktime'])$wdCheck=true;
						}
						if($_POST['worktime']>8 && $_POST['worktime']<24)
						{
							if($toHour>8 && $toHour<24 && $toHour>=$_POST['worktime'])$wdCheck=true;
						}
					}
				}
			}
		}
		return $wdCheck;	}}
?>